import { ref, onMounted } from "vue";
import { getAction } from "@/command/netTool";
import { useRouter } from "vue-router";
import { useDetail } from "@/hooks";
import { getUserInfoUrl, getUserType } from "@/command/apiTool";
export const useRequest = () => {
  const router = useRouter();
  const form = ref({
    phone: "",
    code: "",
  });
  onMounted(() => {
    getAction("/api/h5/farmer/userInfo").then((e) => {
      localStorage.setItem("userInfo", JSON.stringify(e));
    });
  });
  // 我的结队
  const [queryMyteam] = useDetail(
    getUserInfoUrl(
      {
        dh: "/api/h5/farmer/teamInfo",
        xh: "/api/h5/farmer/teamInfoForXh",
      },
      {
        userType: getUserType(),
      }
    ),
    []
  );
  // 最新快讯
  const [newInfoList] = useDetail(
    getUserInfoUrl({
      dh: "",
      xh: "/api/h5/richInspection/small/queryKz",
    }),
    [
      {
        phone: "",
        beforeTime: "",
      },
    ]
  );
  const [teamNewInfo] = useDetail("/api/h5/farmer/teamNewInfo", {
    beforeTime: "",
    id: "",
    info: "",
    phone: "",
  });
  const [topUserInfo] = useDetail("/api/h5/farmer/topUserInfo", {
    productTypeName: "",
    mccName: "",
    userName: "",
  });

  // 结对的农户详情 -  小户
  const [myDhTeam] = useDetail(
    getUserInfoUrl({
      dh: "",
      xh: "", // /api/h5/farmer/teamUserDetail
    }),
    []
  );
  return {
    form,
    // topUserInfo,
    queryMyteam,
    newInfoList,
    teamNewInfo,
    topUserInfo,
    myDhTeam,
  };
};
